{% load humanize %}

<div class="col-12 table-responsive">
    {# 계약자 리스트 #}
    <div class="row">
        <div class="col-sm"><h5><i class="dripicons-view-apps text-primary"></i> 계약현황</h5></div>
        <div class="col-sm text-right mr-2">
            <span class="text-black-50 mr-3">총 계약 건수 : {{ contract_count }} 건</span>
            <a href="javascript:" onclick="$('#output_option').toggle();">[엑셀 출력항목 선택]</a>
            <a href="javascript:"
               onclick="excel('{% url 'excel:contracts' %}?project={{ this_project.id }}&group={{ request.GET.group }}&type={{ request.GET.type }}&dong={{ request.GET.dong }}&status={{ request.GET.status }}&reg={{ request.GET.register }}&sdate={{ request.GET.sdate }}&edate={{ request.GET.edate }}&q={{ request.GET.q }}')"
               class="ml-3">
                <i class="mdi mdi-file-excel-box"></i> Excel Export
                <i class="mdi mdi-download ml-1"></i>
            </a>
        </div>
    </div>

    <div class="col-sm-12 form-inline p-1 bg-info-lighten" id="output_option" style="display:none;">
        <div class="checkbox p-1"><label><input type="checkbox" name="opt1" class="mr-1" checked disabled> 일련번호&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt2" class="mr-1" checked> 인가여부&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt3" class="mr-1" checked> 차수&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt4" class="mr-1" checked> 타입&nbsp;</label></div>
        {% if this_project.is_unit_set %}
            <div class="checkbox p-1"><label><input type="checkbox" name="opt5" class="mr-1" checked> 동호수&nbsp;</label></div>
        {% endif %}
        <div class="checkbox p-1"><label><input type="checkbox" name="opt6" class="mr-1" checked> 계약자&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt7" class="mr-1" checked> 생년월일&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt8" class="mr-1" checked> 계약일자&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt9" class="mr-1" checked> 연락처[1]&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt10" class="mr-1"> 연락처[2]&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt11" class="mr-1"> 연락처[3]&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt12" class="mr-1"> 이메일&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt13" class="mr-1"> 주소[등본]&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt14" class="mr-1" checked> 주소[우편]&nbsp;</label></div>
        <div class="checkbox p-1"><label><input type="checkbox" name="opt15" class="mr-1"> 비고</label></div>
    </div>


    <table id="scroll-horizontal-datatable"
           class="table table-hover table-centered table-condensed table-sm w-100 m-0 nowrap"
           style="word-break: keep-all;">
        <thead>
        <tr class="bg-nav-pills">
            <th scope="col"><input type="checkbox" disabled></th>
            <th class="text-center" scope="col">일련 번호</th>
            <th class="text-center" scope="col">차 수</th>
            <th class="text-center" scope="col">타 입</th>
            {% if this_project.is_unit_set %}
                <th class="text-center" scope="col">동호수</th>{% endif %}
            <th class="text-center" scope="col">계약자</th>
            <th class="text-center" scope="col">최근 납입회차</th>
            <th class="text-center" scope="col">최근 납입금액</th>
            <th class="text-center" scope="col">인가 등록여부</th>
            <th class="text-center" scope="col">연락처[1]</th>
            <th class="text-center" scope="col">계약자 거주지역</th>
            <th class="text-center" scope="col">계약일자</th>
        </tr>
        </thead>
        <tbody>
        {% for object in object_list %}
            <tr class="{% if object.contractor.contractorrelease.status == '3' %}bg-warning-lighten{% endif %}">
                <th scope="row"><input type="checkbox" disabled></th>
                <td class="text-center" {% if object.contractor.status == '3' %}data-toggle="popover"
                    data-trigger="hover" title="" data-content="해지신청 상태" data-original-title=""{% endif %}>
                    <a href="{% url 'rebs:contract:register' %}?project={{ object.project_id }}&task=2&order_group={{ object.order_group.id }}&type={{ object.contractunit.unit_type.id }}&contract_unit={{ object.contractunit.id }}&unit_number={{ object.contractunit.unitnumber.id }}&cont_id={{ object.id }}&p={{ request.GET.page }}&l={{ request.GET.limit }}&g={{ request.GET.group }}&t={{ request.GET.type }}&d={{ request.GET.dong }}&s={{ request.GET.status }}&r={{ request.GET.register }}&o={{ request.GET.order }}&sd={{ request.GET.sdate }}&ed={{ request.GET.edate }}&q={{ request.GET.q }}">
                        {{ object.serial_number }}
                    </a>
                </td>
                <td class="text-center">{{ object.order_group }}</td>
                <td><i class="mdi mdi-square"
                       style="color: {{ object.contractunit.unit_type.color }};"></i> {{ object.contractunit.unit_type }}
                </td>
                {% if this_project.is_unit_set %}
                    <td class="text-center">{{ object.contractunit.unitnumber }}</td>{% endif %}
                <td class="text-center"
                    {% if object.contractor.contractorrelease.status == '3' %}data-toggle="popover"
                    data-trigger="hover" title="" data-content="해지신청 상태" data-original-title=""{% endif %}>
                    <a href="{% url 'rebs:contract:register' %}?project={{ object.project_id }}&task=2&order_group={{ object.order_group.id }}&type={{ object.contractunit.unit_type.id }}&contract_unit={{ object.contractunit.id }}&unit_number={{ object.contractunit.unitnumber.id }}&cont_id={{ object.id }}&p={{ request.GET.page }}&l={{ request.GET.limit }}&g={{ request.GET.group }}&t={{ request.GET.type }}&d={{ request.GET.dong }}&s={{ request.GET.status }}&r={{ request.GET.register }}&o={{ request.GET.order }}&sd={{ request.GET.sdate }}&ed={{ request.GET.edate }}&q={{ request.GET.q }}">
                        {{ object.contractor.name }}
                    </a>
                </td>
                <td class="text-center">{{ object.projectcashbook_set.first.installment_order }}</td>
                <td class="text-right">{{ object.projectcashbook_set.first.income|intcomma }}</td>
                <td class="pl-5">
                    <i class="mdi mdi-circle text-{% if object.contractor.is_registed %}success{% else %}danger{% endif %}"></i>
                    {% if object.contractor.is_registed %}인가{% else %}미인가{% endif %}
                </td>
                <td class="text-center">{{ object.contractor.contractorcontact.cell_phone }}</td>
                <td class="text-center">{{ object.contractor.contractoraddress.dm_address1|truncatewords:"2" }}</td>
                <td class="text-center">{{ object.contractor.contract_date|date:"Y-m-d" }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
</div>

{% block third_party_js %}
    <script>

      function excel(url){
			var opt = "1";
			if(document.form1.opt2.checked===true) var opt = opt+"-2";
			if(document.form1.opt3.checked===true) var opt = opt+"-3";
			if(document.form1.opt4.checked===true) var opt = opt+"-4";
        {% if this_project.is_unit_set %}
			if(document.form1.opt5.checked===true) var opt = opt+"-5-6";
        {% endif %}
			if(document.form1.opt6.checked===true) var opt = opt+"-7";
			if(document.form1.opt7.checked===true) var opt = opt+"-8";
			if(document.form1.opt8.checked===true) var opt = opt+"-9";
			if(document.form1.opt9.checked===true) var opt = opt+"-10";
			if(document.form1.opt10.checked===true) var opt = opt+"-11";
			if(document.form1.opt11.checked===true) var opt = opt+"-12";
			if(document.form1.opt12.checked===true) var opt = opt+"-13";
			if(document.form1.opt13.checked===true) var opt = opt+"-14-15-16-17";
			if(document.form1.opt14.checked===true) var opt = opt+"-18-19-20-21";
			if(document.form1.opt15.checked===true) var opt = opt+"-22";

			location.href = url+"&col="+opt;
		}
    </script>
{% endblock %}
